<?php

/**
 * This is the model class for table "mst_pegawai".
 *
 * The followings are the available columns in table 'mst_pegawai':
 * @property string $id_pegawai
 * @property string $nama
 * @property string $nip
 * @property string $alamat
 * @property string $no_telp
 * @property string $id_jabatan
 * @property string $password
 * @property string $id_group
 *
 * The followings are the available model relations:
 * @property Group $idGroup
 * @property Jabatan $idJabatan
 */
class Pegawai extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Pegawai the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'mst_pegawai';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nama, nip, id_jabatan, password, id_group', 'required'),
			array('nama', 'length', 'max'=>50),
			array('nip', 'length', 'max'=>45),
			array('alamat', 'length', 'max'=>200),
			array('no_telp', 'length', 'max'=>15),
			array('id_jabatan, id_group', 'length', 'max'=>20),
			array('password', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_pegawai, nama, nip, alamat, no_telp, id_jabatan, password, id_group', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'Group' => array(self::BELONGS_TO, 'Group', 'id_group'),
			'Jabatan' => array(self::BELONGS_TO, 'Jabatan', 'id_jabatan'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_pegawai' => 'Id Pegawai',
			'nama' => 'Nama',
			'nip' => 'Nip',
			'alamat' => 'Alamat',
			'no_telp' => 'No Telp',
			'id_jabatan' => 'Id Jabatan',
			'password' => 'Password',
			'id_group' => 'Gup Pengguna',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_pegawai',$this->id_pegawai,true);
		$criteria->compare('nama',$this->nama,true);
		$criteria->compare('nip',$this->nip,true);
		$criteria->compare('alamat',$this->alamat,true);
		$criteria->compare('no_telp',$this->no_telp,true);
		$criteria->compare('id_jabatan',$this->id_jabatan,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('id_group',$this->id_group,true);
                $criteria->with = array('Jabatan');
                
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}